package com.credentials;

import com.commonfunction.CommFunction;
import com.login.LoginFunctions;
import com.opensymphony.xwork2.ActionSupport;

public class SaveCredentials extends ActionSupport{
	private String originaluser,newuser,newpass,confpass;

	public String getOriginaluser() {
		return originaluser;
	}

	public void setOriginaluser(String originaluser) {
		this.originaluser = originaluser;
	}

	public String getNewuser() {
		return newuser;
	}

	public void setNewuser(String newuser) {
		this.newuser = newuser;
	}

	public String getNewpass() {
		return newpass;
	}

	public void setNewpass(String newpass) {
		this.newpass = newpass;
	}

	public String getConfpass() {
		return confpass;
	}

	public void setConfpass(String confpass) {
		this.confpass = confpass;
	}
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		addActionMessage("Username password saved");
		System.out.println(originaluser+":"+newuser+":"+newpass+":"+confpass);
		CredentialFunction credentialFunction = new CredentialFunction();
		if (credentialFunction.saveCredentials(originaluser, newuser, newpass)) {
			return "success";
		}else{
			return "fail";
		}
		
	}
	
	@Override
	public void validate() {
		// TODO Auto-generated method stub
		LoginFunctions loginFunctions = new LoginFunctions();
		if (!originaluser.equals(newuser) && loginFunctions.isUserPresent(newuser)) {
		
				addActionError("User id present you cannot use it");
		
			
		}
	}
}
